﻿using System.Data;

namespace DAL
{
    public static class DalUser
    {
        private static readonly clsConnect Cls = new clsConnect();
        #region[Get-Data]
        public static DataTable GetUser(string keywords)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@KEYWORDS", keywords);
            return Cls.GetData("sp_Login_User_Get");
        }
        public static DataTable GetUserEdit(int id)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@Users_Id", id);
            return Cls.GetData("sp_Login_User_Get_Edit");
        }
        public static DataTable GetUserFillter(int groupUser)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@USer_Detail_Id", groupUser);
            return Cls.GetData("sp_Login_User_Get_Fillter");
        }
        #endregion

        #region[Insert-Update-Delete]
        public static bool Insert(EtUser obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@UserName", obj.UserName);
            Cls.AddParameter("@Passwords", obj.Passwords);
            Cls.AddParameter("@Employee_Id", obj.EmployeeId);
            Cls.AddParameter("@USer_Detail_Id", obj.USerDetailId);
            Cls.AddParameter("@IsActive", obj.IsActive);
            Cls.AddParameter("@IsUsed", obj.IsUsed);
            Cls.AddParameter("@Note", obj.Note);
            obj.msg = Cls.ExecuteNonQueryOutput("sp_Login_User_Insert", "@MSG");
            return true;
        }
        public static bool Update(EtUser obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@Users_Id", obj.UsersId);
            Cls.AddParameter("@UserName", obj.UserName);
            Cls.AddParameter("@Passwords", obj.Passwords);
            Cls.AddParameter("@Employee_Id", obj.EmployeeId);
            Cls.AddParameter("@USer_Detail_Id", obj.USerDetailId);
            Cls.AddParameter("@IsActive", obj.IsActive);
            Cls.AddParameter("@Note", obj.Note);
            return Cls.ExecuteNonQuery("sp_Login_User_Update");
        }
        public static bool UpdateLastLogin(EtUser obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@Users_Id", obj.UsersId);
            return Cls.ExecuteNonQuery("sp_Login_User_UpdateLastLogin");
        }
        public static bool Delete(EtUser obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@Users_Id", obj.UsersId);
            obj.msg = Cls.ExecuteNonQueryOutput("sp_Login_User_Del", "@MSG");
            return true;
        }
        public static bool ChangePass(EtUser obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@Users_Id", obj.UsersId);
            Cls.AddParameter("@Passwords", obj.Passwords);
            return Cls.ExecuteNonQuery("sp_Login_User_ChangePass");
        }
        #endregion
    }
    public class EtUser
    {
        public int UsersId { get; set; }
        public string UserName { get; set; }
        public string Passwords { get; set; }
        public int EmployeeId { get; set; }
        public int USerDetailId { get; set; }
        public bool IsActive { get; set; }
        public bool IsUsed { get; set; }
        public int msg { get; set; }
        public string Note { get; set; }
    }
}
